package com.gxnu.edu.cn.ttxxt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxnu.edu.cn.ttxxt.entity.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserRepository extends BaseMapper<Users> {

    @Select("SELECT * FROM users WHERE username = #{username}")
    Users findByUsername(@Param("username") String username);

    @Select("SELECT * FROM users WHERE phone = #{phone}")
    Users findByPhone(@Param("phone") String phone);

    @Select("SELECT * FROM users WHERE email = #{email}")
    Users findByEmail(@Param("email") String email);

    @Select("SELECT COUNT(*) > 0 FROM users WHERE username = #{username}")
    boolean existsByUsername(@Param("username") String username);

    @Select("SELECT COUNT(*) > 0 FROM users WHERE phone = #{phone}")
    boolean existsByPhone(@Param("phone") String phone);

    @Select("SELECT COUNT(*) > 0 FROM users WHERE email = #{email}")
    boolean existsByEmail(@Param("email") String email);

    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    Users selectById1(Long userId);


    @Update("UPDATE users SET username = #{username}, phone = #{phone}, email = #{email},signature = #{signature}, update_time = #{updateTime} WHERE user_id = #{userId}")
    void updateUsers(Users users);

    @Update("UPDATE users SET  ip = #{ip} WHERE user_id = #{userId}")
    void updateUsersIp(Users users);

}